package com.guandeng.mall.portal.service.impl;

import com.guandeng.mall.model.UmsMember;
import com.guandeng.mall.portal.service.MemberCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.guandeng.mall.security.service.RedisService;

@Service
public class MemberCacheServiceImpl implements MemberCacheService {
    @Autowired
    private RedisService redisService;

    @Value("${redis.database}")
    private String REDIS_DATABASE;

    @Value("${redis.key.authCode")
    private String REDIS_KEY_AUTH_CODE;

    @Value("${redis.expire.common}")
    private Long REDIS_EXPIRE;

    @Override
    public String getAuthCode(String telphone) {
        String key = REDIS_DATABASE + ":" + REDIS_KEY_AUTH_CODE + ":" + telphone;
        return (String) redisService.get(key);
    }
    @Override
    public UmsMember getMember(String username) {
        String key = REDIS_DATABASE + ":" + REDIS_KEY_AUTH_CODE + ":" + username;
        return (UmsMember) redisService.get(key);
    }

    @Override
    public void setMember(UmsMember member) {
        String key = REDIS_DATABASE + ":" + REDIS_KEY_AUTH_CODE + ":" + member.getUsername();
        redisService.set(key, member, REDIS_EXPIRE);
    }

}
